class ConsultaAudit < Consulta
  def self.audits(auditable_type,user_id,username,action,page)
    @auditable_type = auditable_type
    @user_id = user_id
    @username = username
    @action = action
    @page = page
    @audits ||= find_audits
  end
  
  def self.find_audits
    Audit.paginate :page => @page, :conditions => conditions,:order => ["created_at DESC"],:per_page => 8
  end
  
  def self.username_conditions
    ["username like ?","%#{@username}%"] unless @username.blank?
  end
  
  def self.auditable_type_conditions
    ["auditable_type like ?","%#{@auditable_type}%"] unless @auditable_type.blank?
  end

  def self.action_conditions
    ["action like ?","%#{@action}%"] unless @action.blank?
  end

  def self.user_id_conditions
    ["user_id = ?",@user_id] unless @user_id.blank?
  end
end
